<template>
  <div class="purchaseUpload">
    <el-form :model="form" ref="form" label-width="150px" class="demo-ruleForm">
      <el-row>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="商品名称">
            <el-input v-model="form.goods_name" disabled></el-input>
            <el-button icon="el-icon-search" style="position: absolute; right: 0px; top: 1px;" @click="getgoods">
            </el-button>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="商品规格">
            <el-input v-model="form.goods_descript" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="商品型号">
            <el-input v-model="form.goods_barcode" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="商品库存">
            <el-input v-model="form.goods_unit" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="新采购数量">
            <el-input v-model="form.pur_numb" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="存放仓库">
            <el-input v-model="form.storage_name" disabled></el-input>
            <el-button icon="el-icon-search" style="position: absolute; right: 0px; top: 1px;" @click="getwarehouse">
            </el-button>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="供应商">
            <el-input v-model="form.su_name" disabled></el-input>
            <el-button icon="el-icon-search" style="position: absolute; right: 0px; top: 1px;" @click="getsupplier">
            </el-button>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="单价">
            <el-input v-model="form.pur_price" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="总折扣">
            <el-input v-model="form.discount" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="总成本">
            <el-input v-model="form.pur_numb_price" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="总运费">
            <el-input v-model="form.pur_freight" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="支付方式">
            <el-select v-model="form.pay_name" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="经办人">
            <el-input v-model="form.employee_name" disabled></el-input>
            <el-button icon="el-icon-search" style="position: absolute; right: 0px; top: 1px;" @click="getadmin">
            </el-button>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="采购日期">
            <el-date-picker
            v-model="form.pur_time"
            type="date"
            placeholder="选择日期">
          </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="10" size="medium">
          <el-form-item class="goodsInput" label="商品备注">
            <el-input v-model="form.pur_remark" type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" clearable>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" class="SearchBtn">
          <el-button type="primary" @click="submitForm" plain>提交信息</el-button>
          <el-button type="warning" @click="resetForm" plain>清空输入</el-button>
          <el-button type="info" @click="returnTo" plain>返回首页</el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
  // import { purchaseAdd, purchaseEdit } from "../../../http/apis/goodsApi/purchase.js"
  import { mapState } from 'vuex'
  export default {
    components: {},
    props: {},
    data() {
      return {
        form: {
          goods_name: '',
          goods_descript: '',
          goods_barcode: '',
          goods_unit: '',
          pur_numb: '',
          storage_name: '',
          su_name: '',
          goods_cost: '',
          discount: '',
          pur_numb_price: '',
          pur_freight: '',
          pay_name: '',
          employee_name: '',
          pur_time: '',
          pur_remark: ''
        },
        options: [{
          value: '0',
          label: '现金付款'
        }, {
          value: '1',
          label: '银行转账'
        }, {
          value: '2',
          label: '支付宝'
        }, {
          value: '3',
          label: '支票'
        }, {
          value: '4',
          label: '其他'
        }]
      };
    },
    watch: {},
    computed: {
      ...mapState('goodsStore', ['Ftype','ADType']),
    },
    methods: {
      // 获取当前日期
      getDate() {
        let time = new Date()
        let day = time.getDate()
        let month = time.getMonth() + 1
        let year = time.getFullYear()
        return (year + '-' + month + '-' + day)
      },
      // 选择获取商品相关数据
      getgoods() {

      },
      // 选择获取供应商相关数据
      getsupplier() {

      },
      // 选择获取仓库相关数据
      getwarehouse() {

      },
      // 选择获取经办人相关数据（外链接表差数据）
      getadmin() {

      },


      // 提交
      submitForm() {
        let data =
        {

        }
        console.log(data)
        return
        // if (this.ADType == 'add') {
        //   purchaseAdd(data)
        //     .then((res) => {
        //       if (res.data.code == "200") {
        //         this.$message({
        //           type: "success",
        //           message: "信息添加成功",
        //         })
        //         this.$router.push('/goods/supplier/supplierMsg')
        //       }
        //     })
        //     .catch((err) => {
        //       console.log("请求失败", err);
        //     });
        // } else if (this.ADType == 'edit') {
        //   console.log(data)
        //   purchaseEdit(data)
        //     .then((res) => {
        //       console.log("成功请求:", res.data.code);
        //       if (res.data.code == "200") {
        //         this.$message({
        //           type: "success",
        //           message: "信息修改成功",
        //         })
        //         this.$router.push('/goods/supplier/supplierMsg')
        //       }
        //     })
        //     .catch((err) => {
        //       console.log("请求失败", err);
        //     });
        // }
      },
      // 清空条件
      resetForm() {
        for (let key in this.form.list) {
          this.form.list[key].data = ''
        }
        this.form.list[10].selectedOptions = ''
        this.formpro = '',
          this.city = ''
      },
      // 返回首页
      returnTo() {
        this.$confirm('即将返回首页，所做的操作无法保存, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          this.$router.push('/goods/supplier/supplierMsg')
        }).catch(() => {
          this.$message({
            type: "info",
            message: "已取消跳转",
            showClose: true,
          });
        });
      }
    },
    created() {
      this.form.pur_time = this.getDate()
      console.log(this.Ftype)
    },
    mounted() { }
  };
</script>

<style lang="scss" scoped>
  .purchaseUpload {
    margin-top: 50px;
  }

  .el-form-item {
    width: 80%;
  }

  .SearchBtn {
    text-align: center;
  }

  .SearchBtn>button {
    margin: 50px 100px 0 0;
  }
</style>